<?php
/**
 * User: hjd-yao
 * Date: 2018/11/26
 * Time: 14:25
 */

namespace Frontend\Http\Controllers;


use App\Http\Controllers\Controller;
use Illuminate\Support\Facades\DB;

class HomeController extends Controller
{
    public function getArea()
    {
        $list = DB::table('sys_area')->where('parent_id','>',0)
            ->select(['id','name','parent_id'])->get();
        $data = [];
        foreach ($list as $key=> $item){
            $data[$key]['title'] = $item->name;
            $data[$key]['pid'] = $item->parent_id;
            if($item->parent_id == 1){
                $data[$key]['pid'] = $item->parent_id-1;
            }
            $data[$key]['id'] = $item->id;
        }
        unset($list);
        return response()->json($data);
    }

}